{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "9c618f8c",
   "metadata": {},
   "source": [
    "# 群丛文件夹"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "82645d8c",
   "metadata": {},
   "outputs": [],
   "source": [
    "source_path = r\"C:\\Users\\luoxi\\Desktop\\273_琐琐荒漠\"\n",
    "\n",
    "空间分布mxd名字 = \"273_琐琐荒漠\"\n",
    "图斑shp名字 = \"437_琐琐荒漠\"\n",
    "#随便挑一个地域mxd,shp复制过来就行\n",
    "占位图路径 = r\"C:\\Users\\luoxi\\Desktop\\1\\123.png\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0c3d81c4",
   "metadata": {},
   "source": [
    "# 对群丛文件的预处理，保证没有打开任何群丛文件夹中的文件、文件夹（很重要）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "47b08651",
   "metadata": {},
   "outputs": [],
   "source": [
    "savecode,savename = 空间分布mxd名字.split(\"_\")[:2]\n",
    "polycode,polyname = 图斑shp名字.split(\"_\")[:2]\n",
    "\n",
    "def rep(st):\n",
    "    st = st.replace(savecode,\"scode\")\n",
    "    st = st.replace(savename,\"sname\")\n",
    "    st = st.replace(polycode,\"pcode\")\n",
    "    st = st.replace(polyname,\"pname\")\n",
    "    return st\n",
    "\n",
    "import os\n",
    "for root,dirs,files in os.walk(source_path,topdown=False): \n",
    "    for file in files:\n",
    "        filename_path=os.path.join(root,file)\n",
    "        new_filename = rep(file)\n",
    "        new_filename_path=os.path.join(root,new_filename)\n",
    "        os.rename(filename_path,new_filename_path)\n",
    "    for dir in dirs:\n",
    "        dir_path=os.path.join(root,dir)\n",
    "        new_dir = rep(dir)\n",
    "        new_dir_path=os.path.join(root,new_dir)\n",
    "        os.rename(dir_path,new_dir_path)\n",
    "\n",
    "filelist = []\n",
    "for root,dirs,files in os.walk(source_path,topdown=False): \n",
    "    for file in files:\n",
    "        filename_path=os.path.join(root,file)\n",
    "        filelist.append(filename_path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "a03bc40d",
   "metadata": {},
   "outputs": [],
   "source": [
    "def add(document,addtype,content,addto = None ,charsize = 1,picsize = (1,1),style = None,mid = False,bold = False,indent = 0):\n",
    "    if addto:\n",
    "        paragraph = addto\n",
    "    else:\n",
    "        paragraph = document.add_paragraph() # 添加新段落\n",
    "    \"\"\"if addtype == \"head\":\n",
    "        run = document.add_heading(content, headlevel)\n",
    "        run.bold = bold\n",
    "        run.font.size = Pt(charsize)\"\"\"\n",
    "    if addtype == \"char\":\n",
    "        run = paragraph.add_run(content,style=style)\n",
    "        run.bold = bold\n",
    "        run.font.size = Pt(charsize)\n",
    "        if mid:\n",
    "            paragraph.paragraph_format.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER\n",
    "        if indent:\n",
    "            paragraph.paragraph_format.first_line_indent = Inches(indent)\n",
    "    elif addtype == \"pic\":\n",
    "        if picsize:\n",
    "            paragraph.add_run().add_picture(content, width=Cm(picsize[0]),height = Cm(picsize[1]))\n",
    "        else:\n",
    "            paragraph.add_run().add_picture(content)\n",
    "        if mid:\n",
    "            paragraph.paragraph_format.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER\n",
    "    return paragraph\n",
    "\n",
    "\n",
    "import pandas as pd\n",
    "\n",
    "def set_cell_border(cell, **kwargs):\n",
    "    \"\"\"\n",
    "    Set cell`s border\n",
    "    Usage:\n",
    "    set_cell_border(\n",
    "        cell,\n",
    "        top={\"sz\": 12, \"val\": \"single\", \"color\": \"#FF0000\", \"space\": \"0\"},\n",
    "        bottom={\"sz\": 12, \"color\": \"#00FF00\", \"val\": \"single\"},\n",
    "        left={\"sz\": 24, \"val\": \"dashed\", \"shadow\": \"true\"},\n",
    "        right={\"sz\": 12, \"val\": \"dashed\"},\n",
    "    )\n",
    "    \"\"\"\n",
    "    tc = cell._tc\n",
    "    tcPr = tc.get_or_add_tcPr()\n",
    "\n",
    "    # check for tag existnace, if none found, then create one\n",
    "    tcBorders = tcPr.first_child_found_in(\"w:tcBorders\")\n",
    "    if tcBorders is None:\n",
    "        tcBorders = OxmlElement('w:tcBorders')\n",
    "        tcPr.append(tcBorders)\n",
    "\n",
    "    # list over all available tags\n",
    "    for edge in ('left', 'top', 'right', 'bottom', 'insideH', 'insideV'):\n",
    "        edge_data = kwargs.get(edge)\n",
    "        if edge_data:\n",
    "            tag = 'w:{}'.format(edge)\n",
    "\n",
    "            # check for tag existnace, if none found, then create one\n",
    "            element = tcBorders.find(qn(tag))\n",
    "            if element is None:\n",
    "                element = OxmlElement(tag)\n",
    "                tcBorders.append(element)\n",
    "\n",
    "            # looks like order of attributes is important\n",
    "            for key in [\"sz\", \"val\", \"color\", \"space\", \"shadow\"]:\n",
    "                if key in edge_data:\n",
    "                    element.set(qn('w:{}'.format(key)), str(edge_data[key]))\n",
    "\n",
    "\n",
    "\n",
    "def temperature_template(bandname):\n",
    "    global piccode,filelist\n",
    "    #获取地域\n",
    "    arealist = []\n",
    "    for i in filelist:\n",
    "        if bandname + \"_\" in i:\n",
    "            c = re.findall(r\"地域([0-9]{1,2})\",i)\n",
    "            arealist += c\n",
    "    arealist = list(set(arealist))\n",
    "    arealist.sort(key = lambda x:int(x))\n",
    "    #print(bandname,\"arealist:\",arealist)\n",
    "    for areacode in arealist:\n",
    "        area_template(bandname,areacode)\n",
    "        \n",
    "def area_template(bandname,areacode):\n",
    "    global piccode,filelist,tablecode\n",
    "    \n",
    "    typelist = []\n",
    "    for i in filelist:\n",
    "        if \"_\" + bandname+ \"\\\\\" in i and \"类型csv\" in i and i.endswith(\".csv\") and i.split(\"\\\\\")[-1].split(\".\")[1] == areacode:\n",
    "            typelist.append(i)\n",
    "        elif \"_\" + bandname+ \"\\\\\" in i and \"类型csv\" in i and i.endswith(\".csv\") and i.split(\"\\\\\")[-1].split(\"-\")[1] == areacode:\n",
    "            typelist.append(i)\n",
    "        if \"_\" + bandname.replace(\"交错带\",\"\") + \"\\\\\" in i and \"类型csv\" in i and i.endswith(\".csv\") and i.split(\"\\\\\")[-1].split(\".\")[1] == areacode:\n",
    "            typelist.append(i)\n",
    "        elif \"_\" + bandname.replace(\"交错带\",\"\") + \"\\\\\" in i and \"类型csv\" in i and i.endswith(\".csv\") and i.split(\"\\\\\")[-1].split(\"-\")[1] == areacode:\n",
    "            typelist.append(i)\n",
    "    try:\n",
    "        typelist.sort(key = lambda x:int(x.split(\".\")[3]))\n",
    "    except:\n",
    "        typelist.sort(key = lambda x:int(x[:-4].split(\"-\")[2]))\n",
    "    #温度带地域简介1\n",
    "    text = savename + f\"{bandname}地域{areacode}位于【【{bandname}地域{areacode}的地理位置】】\"\n",
    "    para = add(document,\"char\",text,charsize = 12,style = \"宋\",indent = 0.2)\n",
    "    #2\n",
    "    def changetypecsv(char):\n",
    "        if \"_\" not in char:\n",
    "            return char.replace(\".0.\",\".\").replace(\".\",\"-\")\n",
    "        else:\n",
    "            key = char.split(\"_\")[-1]\n",
    "            return key + \"-\" + char.split(\"_\")[0].split(\".\")[1] + \"-\" + char.split(\"_\")[0].split(\".\")[3]\n",
    "    t = \"、\".join(changetypecsv(i.split(\"\\\\\")[-1][:-4]) for i in typelist)\n",
    "    text = f\"有{len(typelist)}个群丛分布（群丛{t}）\"\n",
    "    para = add(document,\"char\",text,addto = para ,charsize = 12,style = \"宋\",indent = 0.2)\n",
    "    #3\n",
    "    maxtb,mintb,maxdem,mindem,maxE,minE = 0,30,-999,99999,-99999,99999\n",
    "    for i in typelist:\n",
    "        df = pd.read_csv(i)\n",
    "        maxtb = max(maxtb,max(df[\"tb\"]))\n",
    "        maxdem = max(maxdem,max(df[\"dem\"]))\n",
    "        maxE = max(maxE,max(df[\"E_sum\"]))\n",
    "        mintb = min(mintb,min(df[\"tb\"]))\n",
    "        mindem = min(mindem,min(df[\"dem\"]))\n",
    "        minE = min(minE,min(df[\"E_sum\"]))\n",
    "\n",
    "    maxtb = int(maxtb) + 1\n",
    "    mintb = int(mintb)\n",
    "    \n",
    "    maxdem = 100* (int(maxdem/100) + 1)\n",
    "    mindem = 100* (int(mindem/100) )\n",
    "    \n",
    "    maxE = 10* (int(maxE/10) + 1)\n",
    "    minE = 10* (int(minE/10) )\n",
    "    \n",
    "    text = f\"海拔在{mindem}至{maxdem}m之间，年生物学温度TB介于{mintb}至{maxtb}℃之间，能量E的范围在{minE}至{maxE}cm之间。\"\n",
    "    add(document,\"char\",text,addto = para ,charsize = 12,style = \"宋\",indent = 0.2)\n",
    "\n",
    "    #图2a 图2b 海拔图，能量图\n",
    "    for i in filelist:\n",
    "        \n",
    "        if i.endswith(f\"{bandname}_地域{areacode}_海拔图.png\") or i.endswith(f\"{bandname}_地域{areacode}_海拔.png\"):\n",
    "            pic1 = i\n",
    "        if i.endswith(f\"{bandname}_地域{areacode}_温度能量.png\") or i.endswith(f\"{bandname}_地域{areacode}_温度能量图.png\"):\n",
    "            pic2 = i\n",
    "    print(bandname,areacode)\n",
    "    para = add(document,\"pic\",pic1,picsize = (7.1,5.81),mid = True)\n",
    "    \n",
    "    add(document,\"pic\",pic2,addto = para ,picsize = (7.1,5.81),mid = True)\n",
    "    \n",
    "    text = \"(a)海拔分布图                     (b)能量温度分布图\"\n",
    "    add(document,\"char\",text,charsize = 10.5,style = \"宋\",mid = True)\n",
    "    \n",
    "    text = f\"图{piccode} {savename}{bandname}地域{areacode}分布图\"\n",
    "    piccode += 1\n",
    "    add(document,\"char\",text,charsize = 10.5,style = \"宋\",mid = True)\n",
    "    #print(\"type\",typelist)\n",
    "    #对类型的阐述\n",
    "    for typ in typelist:\n",
    "        df = pd.read_csv(typ)\n",
    "        newname = changetypecsv(typ.split(\"\\\\\")[-1][:-4])\n",
    "        lines = []\n",
    "        for j in filelist:\n",
    "            if newname + \".svg\" in j:\n",
    "                with open(j, 'r',encoding = \"utf8\") as f:\n",
    "                    c = f.read()\n",
    "                    lines = re.findall(\"<!-- (E=.*?) -->\",c) + re.findall(\"<!-- (TB=.*?) -->\",c)\n",
    "                break\n",
    "        lines = [c.replace(\"&lt;\",\"<\") for c in lines]\n",
    "        if not lines:\n",
    "            print(f\"没查到群丛{newname}svg中的斜率\")\n",
    "            continue\n",
    "        text = f\"群丛{newname}共计{len(df)}个样本点，如图{piccode+1}所示，\"\n",
    "        para = add(document,\"char\",text,charsize = 12,style = \"宋\",indent = 0.2)\n",
    "        \n",
    "        if len(lines )> 1:\n",
    "            text = f\"【【拟合线太多没想好这里怎么写】】\"\n",
    "            para = add(document,\"char\",text,addto = para,charsize = 12,style = \"宋\",indent = 0.2)\n",
    "        elif not lines:\n",
    "            text = f\"【【没有拟合线】】\"\n",
    "            add(document,\"char\",text,charsize = 12,style = \"宋\")\n",
    "        else:\n",
    "            g = \"正\" if \"E=-\" not in lines[0] else \"负\"\n",
    "            text = f\"TB和E之间呈显著{g}相关（P＜0.05）\"\n",
    "            para = add(document,\"char\",text,addto = para,charsize = 12,style = \"宋\")\n",
    "            \n",
    "            a,b = round(sum(df[\"tb\"])/len(df),2),round(sum(df[\"E_sum\"])/len(df),2)\n",
    "            text = f\"，线性拟合方程为{lines[0]}，均值点为（{a},{b}），\"\n",
    "            para = add(document,\"char\",text,addto = para,charsize = 12,style = \"宋\")\n",
    "        \n",
    "        text = f\"主要分布于{bandname}范围内的【【？】】下，PE/P的值大于【【？】】，表示该群丛处于【【？】】。\"\n",
    "        add(document,\"char\",text,addto = para,charsize = 12,style = \"宋\")\n",
    "\n",
    "\n",
    "        add(document,\"pic\",占位图路径,picsize = (10,6),mid = True)\n",
    "        text = f\"图{piccode} 群丛{newname} TB-E坐标系分布图\"\n",
    "        piccode += 1\n",
    "        add(document,\"char\",text,charsize = 10.5,style = \"宋\",mid = True)\n",
    "\n",
    "        text = f\"根据所圈定小区域范围，群丛{newname}的演替概率如图{piccode}及表{tablecode}所示。表{tablecode}列举了该区域内各群系样本点状态的占比，对应分布情况如图{piccode}所示。\"\n",
    "        add(document,\"char\",text,charsize = 12,style = \"宋\",indent = 0.2)\n",
    "\n",
    "        for c in filelist:\n",
    "            a = newname.split(\"-\")[-1]\n",
    "            if c.endswith(f\"{bandname}_地域{areacode}_类型{a}_演替.png\"):\n",
    "                pic1 = c\n",
    "                break\n",
    "        add(document,\"pic\",pic1,picsize = (13,8.5),mid = True)\n",
    "        text = f\"图{piccode} 群丛{newname}演替图\"\n",
    "        piccode += 1\n",
    "        add(document,\"char\",text,charsize = 10.5,style = \"宋\",mid = True)\n",
    "\n",
    "        text = f\"表{tablecode} 群丛{newname}演替图稳态分析\"\n",
    "        tablecode += 1\n",
    "        add(document,\"char\",text,charsize = 10.5,style = \"宋\",mid = True)\n",
    "\n",
    "        table = document.add_table(rows=1, cols=9,style=None)\n",
    "        table.alignment=WD_TABLE_ALIGNMENT.CENTER\n",
    "\n",
    "        #写标题行，并设置字体\n",
    "        hdr_cells = table.rows[0].cells\n",
    "        Fields=\"value\t说明书编号\t其余点\t95%内&稳态\t95%外&稳态\t95%内&亚稳态\t95%外&亚稳态\t95%内&混沌态\t95%外&混沌态\".split(\"\\t\")\n",
    "\n",
    "        for aa in range(9):\n",
    "            set_cell_border(\n",
    "            hdr_cells[aa],\n",
    "            top={\"sz\": 0.5,\"val\" : \"single\", \"color\": \"#000000\", \"space\": \"0\"},\n",
    "            bottom={\"sz\": 0.5, \"val\" : \"single\",\"color\": \"#000000\", \"space\": \"0\"},)\n",
    "\n",
    "        for i in range(9):\n",
    "            hdr_cells[i].paragraphs[0].paragraph_format.alignment=WD_ALIGN_PARAGRAPH.CENTER\n",
    "\n",
    "            run=hdr_cells[i].paragraphs[0].add_run(Fields[i],style = \"新罗马\")\n",
    "            run.font.size = Pt(10.5)\n",
    "            run.font.bold=True\n",
    "\n",
    "        for c in filelist:\n",
    "            a = newname.split(\"-\")[-1]\n",
    "            if c.endswith(f\"{bandname}_地域{areacode}_类型{a}_演替.csv\"):\n",
    "                df = pd.read_csv(c)\n",
    "                break\n",
    "\n",
    "        for i in range(len(df)):\n",
    "            total = 0\n",
    "            for a in [0,1,2]:\n",
    "                for b in [1,2,3]:\n",
    "                    total += df[f\"c1={a}&c2={b}\"][i]\n",
    "            ld = [df[\"value\"][i],\"没想好\",\n",
    "                  str(round(df[\"c1=0&c2=3\"]/total,2)[i])+\"%\",\n",
    "                  str(round(df[\"c1=1&c2=1\"]/total,2)[i])+\"%\",\n",
    "                  str(round(df[\"c1=2&c2=1\"]/total,2)[i])+\"%\",\n",
    "                  str(round(df[\"c1=1&c2=2\"]/total,2)[i])+\"%\",\n",
    "                  str(round(df[\"c1=2&c2=2\"]/total,2)[i])+\"%\",\n",
    "                  str(round(df[\"c1=1&c2=3\"]/total,2)[i])+\"%\",\n",
    "                  str(round(df[\"c1=2&c2=3\"]/total,2)[i])+\"%\",\n",
    "                 ]\n",
    "\n",
    "            row_cells = table.add_row().cells\n",
    "            for g in range(9):\n",
    "                row_cells[g].paragraphs[0].paragraph_format.alignment=WD_ALIGN_PARAGRAPH.CENTER\n",
    "                run=row_cells[g].paragraphs[0].add_run(str(ld[g]),style = \"新罗马\")\n",
    "                run.font.size = Pt(10.5)\n",
    "        table.cell(0,0).width = Cm(1.15)\n",
    "        table.cell(0,1).width = Cm(1.5)\n",
    "        table.cell(0,2).width = Cm(1.5)\n",
    "        for i in range(3,5):\n",
    "            table.cell(0,i).width = Cm(1.7)\n",
    "        for i in range(5,9):\n",
    "            table.cell(0,i).width = Cm(1.96)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "513a68ce",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "c86f86bb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "中温带 1\n",
      "中温带 2\n",
      "中温带 3\n",
      "中温带 4\n",
      "中温带 5\n",
      "中温带 6\n",
      "中温带 7\n",
      "中温带 8\n",
      "中温带 9\n",
      "中温带 10\n",
      "暖温带 1\n",
      "暖温带 2\n",
      "暖温带 3\n",
      "暖温带 4\n",
      "暖温带 5\n",
      "暖温带 6\n",
      "暖温带 7\n",
      "暖温带 8\n",
      "暖温带 9\n",
      "暖温带 10\n",
      "暖温带 11\n",
      "中温带-暖温带交错带 1\n",
      "没查到群丛3-4-1-1svg中的斜率\n"
     ]
    }
   ],
   "source": [
    "from docx import Document\n",
    "from docx.shared import Cm, Pt\n",
    "from docx.document import Document as Doc\n",
    "from docx.oxml.ns import qn\n",
    "from docx.enum.style import WD_STYLE_TYPE\n",
    "from docx.enum.text import WD_PARAGRAPH_ALIGNMENT,WD_ALIGN_PARAGRAPH\n",
    "from docx.enum.table import WD_TABLE_ALIGNMENT\n",
    "from docx.shared import Inches\n",
    "from docx.oxml import OxmlElement\n",
    "import re\n",
    "document = Document()\n",
    "\n",
    "style_song = document.styles.add_style('宋', WD_STYLE_TYPE.CHARACTER)\n",
    "style_song.font.name = '宋体'\n",
    "document.styles['宋']._element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体')\n",
    "\n",
    "style_song = document.styles.add_style('黑', WD_STYLE_TYPE.CHARACTER)\n",
    "style_song.font.name = '黑体'\n",
    "document.styles['黑']._element.rPr.rFonts.set(qn('w:eastAsia'), u'黑体')\n",
    "\n",
    "style_song = document.styles.add_style('新罗马', WD_STYLE_TYPE.CHARACTER)\n",
    "style_song.font.name = 'Times new Roman'\n",
    "document.styles['新罗马']._element.rPr.rFonts.set(qn('w:eastAsia'), u'Times new Roman')\n",
    "\n",
    "piccode = 1\n",
    "tablecode = 1\n",
    "\n",
    "\n",
    "#大标题\n",
    "text = savecode + savename + \"的自组织格局与演替\"\n",
    "add(document,\"char\",text,charsize = 15,bold = True,style = \"黑\")\n",
    "\n",
    "#二标题\n",
    "text = \"1. 群丛的分布格局与演替\"\n",
    "add(document,\"char\",text,charsize = 15,bold = True,style = \"黑\")\n",
    "\n",
    "#小正文\n",
    "text = savename + \"【【广泛分布于我国生境+地区（如西北干旱区），在群丛所涉及的地理区域都有分布。这段最好自己写】】\"\n",
    "add(document,\"char\",text,charsize = 12,style = \"宋\",indent = 0.2)\n",
    "\n",
    "#图1 空间分布图\n",
    "for i in filelist:\n",
    "    if \"scode_sname_空间分布.png\" in i or \"scode_sname.png\" in i :\n",
    "        pic = i\n",
    "add(document,\"pic\",pic,picsize = (8,6.54),mid = True)\n",
    "\n",
    "text = f\"图{piccode} \" + savename + \"空间分布图\"\n",
    "piccode += 1\n",
    "add(document,\"char\",text,charsize = 10.5,style = \"宋\",mid = True)\n",
    "        \n",
    "    \n",
    "#对地域的阐述    \n",
    "bandlist = []\n",
    "for i in filelist:\n",
    "    if \"scode_sname\" in i.split(\"\\\\\")[-1]:\n",
    "        try:\n",
    "            key = i.split(\"\\\\\")[-1].split(\".\")[0].split(\"_\")[2]\n",
    "        except:\n",
    "            continue\n",
    "        if  key not in bandlist and \"带\" in key and \"高\" not in key and \"分布\" not in key:\n",
    "            bandlist.append(key)\n",
    "def sortkey(char):\n",
    "    code = 0\n",
    "    tempr = ['交错带','极地苔原带','寒温带','中温带','暖温带','亚热带']\n",
    "    for index,temp in enumerate(tempr):\n",
    "        if temp in char:\n",
    "            code += 10**index\n",
    "    if \"交错带\" in char:\n",
    "        code += 10000000\n",
    "    if \"热带\" in char.replace(\"亚热带\",\"\"):\n",
    "        code += 10**7\n",
    "    return code\n",
    "bandlist.sort(key = lambda x :sortkey(x))\n",
    "\n",
    "def sortkey(char):\n",
    "    code = 0\n",
    "    if \"_\" in char:\n",
    "        for i in char.split(\"_\")[-1][:-4].split(\".\"):\n",
    "            code += 10**int(i)\n",
    "    code += 1* int(char.split(\".\")[1])\n",
    "    code += 0.01 *int(char.split(\".\")[3])\n",
    "    return code\n",
    "\n",
    "\"\"\"typelist = []\n",
    "for i in filelist:\n",
    "    if \"类型csv\" in i and i.endswith(\".csv\"):\n",
    "        typelist.append(i.split(\"\\\\\")[-1])  \n",
    "typelist.sort(key = lambda x :sortkey(x) )\n",
    "   \n",
    "countl = [1,1,1,1,1,1,1,1,1]\n",
    "typedict = {}\n",
    "for i in typelist:\n",
    "    typedict[i] = i.split(\".\")[0] + \".\" + str(countl[int(i.split(\".\")[0])])\n",
    "    countl[int(i.split(\".\")[0])] += 1\n",
    "    \"\"\"\n",
    "    \n",
    "for band in bandlist:\n",
    "    temperature_template(band)\n",
    "    \n",
    "    \n",
    "document.save('test.docx') # 存储WORD文档\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "48cd7a4e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\基础\\\\scode_sname_各类型信息统计.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_0_温度交错带\\\\scode_sname_3.4_中温带-暖温带\\\\地域csv\\\\scode_sname 中温带-暖温带交错带_地域1_格子图占比.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_0_温度交错带\\\\scode_sname_3.4_中温带-暖温带\\\\地域csv\\\\scode_sname_中温带-暖温带交错带_地域1.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_0_温度交错带\\\\scode_sname_3.4_中温带-暖温带\\\\演替图\\\\scode_sname_中温带-暖温带交错带_地域1_类型1_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_0_温度交错带\\\\scode_sname_3.4_中温带-暖温带\\\\类型csv\\\\3.4-1-1.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_0_温度交错带\\\\scode_sname_3.4_中温带-暖温带\\\\scode_sname_中温带-暖温带交错带_各类型信息统计.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\地域csv\\\\scode_sname 中温带_地域10_格子图占比.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\地域csv\\\\scode_sname 中温带_地域1_格子图占比.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\地域csv\\\\scode_sname 中温带_地域2_格子图占比.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\地域csv\\\\scode_sname 中温带_地域3_格子图占比.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\地域csv\\\\scode_sname 中温带_地域4_格子图占比.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\地域csv\\\\scode_sname 中温带_地域5_格子图占比.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\地域csv\\\\scode_sname 中温带_地域6_格子图占比.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\地域csv\\\\scode_sname 中温带_地域7_格子图占比.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\地域csv\\\\scode_sname 中温带_地域8_格子图占比.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\地域csv\\\\scode_sname 中温带_地域9_格子图占比.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\地域csv\\\\scode_sname_中温带_地域1.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\地域csv\\\\scode_sname_中温带_地域10.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\地域csv\\\\scode_sname_中温带_地域2.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\地域csv\\\\scode_sname_中温带_地域3.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\地域csv\\\\scode_sname_中温带_地域4.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\地域csv\\\\scode_sname_中温带_地域5.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\地域csv\\\\scode_sname_中温带_地域6.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\地域csv\\\\scode_sname_中温带_地域7.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\地域csv\\\\scode_sname_中温带_地域8.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\地域csv\\\\scode_sname_中温带_地域9.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\演替图\\\\scode_sname_中温带_地域10_类型1_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\演替图\\\\scode_sname_中温带_地域1_类型1_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\演替图\\\\scode_sname_中温带_地域1_类型2_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\演替图\\\\scode_sname_中温带_地域1_类型3_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\演替图\\\\scode_sname_中温带_地域2_类型1_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\演替图\\\\scode_sname_中温带_地域3_类型1_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\演替图\\\\scode_sname_中温带_地域4_类型1_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\演替图\\\\scode_sname_中温带_地域4_类型2_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\演替图\\\\scode_sname_中温带_地域4_类型3_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\演替图\\\\scode_sname_中温带_地域5_类型1_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\演替图\\\\scode_sname_中温带_地域5_类型2_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\演替图\\\\scode_sname_中温带_地域5_类型3_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\演替图\\\\scode_sname_中温带_地域5_类型4_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\演替图\\\\scode_sname_中温带_地域5_类型5_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\演替图\\\\scode_sname_中温带_地域5_类型6_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\演替图\\\\scode_sname_中温带_地域6_类型1_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\演替图\\\\scode_sname_中温带_地域6_类型2_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\演替图\\\\scode_sname_中温带_地域7_类型1_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\演替图\\\\scode_sname_中温带_地域8_类型1_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\演替图\\\\scode_sname_中温带_地域9_类型1_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\类型csv\\\\3-1-1.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\类型csv\\\\3-1-2.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\类型csv\\\\3-1-3.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\类型csv\\\\3-10-1.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\类型csv\\\\3-2-1.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\类型csv\\\\3-3-1.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\类型csv\\\\3-4-1.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\类型csv\\\\3-4-2.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\类型csv\\\\3-4-3.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\类型csv\\\\3-5-1.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\类型csv\\\\3-5-2.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\类型csv\\\\3-5-3.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\类型csv\\\\3-5-4.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\类型csv\\\\3-5-5.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\类型csv\\\\3-5-6.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\类型csv\\\\3-6-1.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\类型csv\\\\3-6-2.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\类型csv\\\\3-7-1.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\类型csv\\\\3-8-1.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\类型csv\\\\3-9-1.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_3_中温带\\\\scode_sname_中温带_各类型信息统计.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\地域csv\\\\scode_sname 暖温带_地域10_格子图占比.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\地域csv\\\\scode_sname 暖温带_地域11_格子图占比.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\地域csv\\\\scode_sname 暖温带_地域1_格子图占比.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\地域csv\\\\scode_sname 暖温带_地域2_格子图占比.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\地域csv\\\\scode_sname 暖温带_地域3_格子图占比.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\地域csv\\\\scode_sname 暖温带_地域4_格子图占比.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\地域csv\\\\scode_sname 暖温带_地域5_格子图占比.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\地域csv\\\\scode_sname 暖温带_地域6_格子图占比.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\地域csv\\\\scode_sname 暖温带_地域7_格子图占比.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\地域csv\\\\scode_sname 暖温带_地域8_格子图占比.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\地域csv\\\\scode_sname 暖温带_地域9_格子图占比.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\地域csv\\\\scode_sname_暖温带_地域1.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\地域csv\\\\scode_sname_暖温带_地域10.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\地域csv\\\\scode_sname_暖温带_地域11.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\地域csv\\\\scode_sname_暖温带_地域2.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\地域csv\\\\scode_sname_暖温带_地域3.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\地域csv\\\\scode_sname_暖温带_地域4.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\地域csv\\\\scode_sname_暖温带_地域5.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\地域csv\\\\scode_sname_暖温带_地域6.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\地域csv\\\\scode_sname_暖温带_地域7.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\地域csv\\\\scode_sname_暖温带_地域8.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\地域csv\\\\scode_sname_暖温带_地域9.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\演替图\\\\scode_sname_暖温带_地域10_类型1_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\演替图\\\\scode_sname_暖温带_地域10_类型2_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\演替图\\\\scode_sname_暖温带_地域10_类型3_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\演替图\\\\scode_sname_暖温带_地域11_类型1_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\演替图\\\\scode_sname_暖温带_地域11_类型2_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\演替图\\\\scode_sname_暖温带_地域11_类型3_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\演替图\\\\scode_sname_暖温带_地域11_类型4_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\演替图\\\\scode_sname_暖温带_地域11_类型5_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\演替图\\\\scode_sname_暖温带_地域1_类型1_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\演替图\\\\scode_sname_暖温带_地域2_类型1_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\演替图\\\\scode_sname_暖温带_地域3_类型1_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\演替图\\\\scode_sname_暖温带_地域3_类型2_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\演替图\\\\scode_sname_暖温带_地域4_类型1_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\演替图\\\\scode_sname_暖温带_地域4_类型2_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\演替图\\\\scode_sname_暖温带_地域4_类型3_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\演替图\\\\scode_sname_暖温带_地域4_类型4_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\演替图\\\\scode_sname_暖温带_地域4_类型5_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\演替图\\\\scode_sname_暖温带_地域5_类型1_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\演替图\\\\scode_sname_暖温带_地域6_类型1_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\演替图\\\\scode_sname_暖温带_地域7_类型1_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\演替图\\\\scode_sname_暖温带_地域8_类型1_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\演替图\\\\scode_sname_暖温带_地域9_类型1_演替.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\类型csv\\\\4-1-1.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\类型csv\\\\4-10-1.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\类型csv\\\\4-10-2.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\类型csv\\\\4-10-3.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\类型csv\\\\4-11-1.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\类型csv\\\\4-11-2.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\类型csv\\\\4-11-3.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\类型csv\\\\4-11-4.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\类型csv\\\\4-11-5.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\类型csv\\\\4-2-1.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\类型csv\\\\4-3-1.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\类型csv\\\\4-3-2.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\类型csv\\\\4-4-1.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\类型csv\\\\4-4-2.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\类型csv\\\\4-4-3.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\类型csv\\\\4-4-4.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\类型csv\\\\4-4-5.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\类型csv\\\\4-5-1.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\类型csv\\\\4-6-1.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\类型csv\\\\4-7-1.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\类型csv\\\\4-8-1.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\类型csv\\\\4-9-1.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\温度带\\\\scode_sname_4_暖温带\\\\scode_sname_暖温带_各类型信息统计.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\123.csv',\n",
       " 'C:\\\\Users\\\\luoxi\\\\Desktop\\\\273_琐琐荒漠\\\\key_ppe_num.csv']"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[i for i in filelist if i.endswith(\".csv\")]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "9f585308",
   "metadata": {},
   "outputs": [
    {
     "ename": "IndentationError",
     "evalue": "expected an indented block (3968152458.py, line 10)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"C:\\Users\\luoxi\\AppData\\Local\\Temp\\ipykernel_19156\\3968152458.py\"\u001b[1;36m, line \u001b[1;32m10\u001b[0m\n\u001b[1;33m    typelist.sort(key = lambda x:int(x.split(\".\")[3]))\u001b[0m\n\u001b[1;37m                                                      ^\u001b[0m\n\u001b[1;31mIndentationError\u001b[0m\u001b[1;31m:\u001b[0m expected an indented block\n"
     ]
    }
   ],
   "source": [
    "typelist = []\n",
    "for i in filelist:\n",
    "    if \"_\" + bandname+ \"\\\\\" in i and \"类型csv\" in i and i.endswith(\".csv\") and i.split(\"\\\\\")[-1].split(\".\")[1] == areacode:\n",
    "        typelist.append(i)\n",
    "    elif \"_\" + bandname+ \"\\\\\" in i and \"类型csv\" in i and i.endswith(\".csv\") and i.split(\"\\\\\")[-1].split(\"-\")[1] == areacode:\n",
    "        typelist.append(i)\n",
    "    if \"_\" + bandname.replace(\"交错带\",\"\") + \"\\\\\" in i and \"类型csv\" in i and i.endswith(\".csv\") and i.split(\"\\\\\")[-1].split(\".\")[1] == areacode:\n",
    "        typelist.append(i)\n",
    "    elif \"_\" + bandname.replace(\"交错带\",\"\") + \"\\\\\" in i and \"类型csv\" in i and i.endswith(\".csv\") and i.split(\"\\\\\")[-1].split(\"-\")[1] == areacode:\n",
    "        \n",
    "typelist.sort(key = lambda x:int(x.split(\".\")[3]))\n",
    "typelist"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "41258f59",
   "metadata": {},
   "outputs": [],
   "source": [
    "bandname = \"中温带\"\n",
    "areacode = \"1\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "6831ea7a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'_中温带\\\\'"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"_\" + bandname+ \"\\\\\" "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6498714a",
   "metadata": {},
   "source": [
    "# 恢复群丛文件夹"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 136,
   "id": "701cd064",
   "metadata": {},
   "outputs": [
    {
     "ename": "PermissionError",
     "evalue": "[WinError 5] 拒绝访问。: 'E:\\\\毕业论文\\\\265+497a_学层杜鹃、髯花杜鹃灌丛+小嵩草高寒草甸（1）\\\\温度带' -> 'E:\\\\毕业论文\\\\265+497a_学层杜鹃、髯花杜鹃灌丛+小嵩草高寒草甸（1）\\\\温度带'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mPermissionError\u001b[0m                           Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_25320\\3456648429.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m     17\u001b[0m         \u001b[0mnew_dir\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mrep\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdir\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     18\u001b[0m         \u001b[0mnew_dir_path\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mos\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpath\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mjoin\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mroot\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mnew_dir\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 19\u001b[1;33m         \u001b[0mos\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrename\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdir_path\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mnew_dir_path\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mPermissionError\u001b[0m: [WinError 5] 拒绝访问。: 'E:\\\\毕业论文\\\\265+497a_学层杜鹃、髯花杜鹃灌丛+小嵩草高寒草甸（1）\\\\温度带' -> 'E:\\\\毕业论文\\\\265+497a_学层杜鹃、髯花杜鹃灌丛+小嵩草高寒草甸（1）\\\\温度带'"
     ]
    }
   ],
   "source": [
    "def rep(st):\n",
    "    st = st.replace(\"scode\",savecode)\n",
    "    st = st.replace(\"sname\",savename)\n",
    "    st = st.replace(\"pcode\",polycode)\n",
    "    st = st.replace(\"pname\",polyname)\n",
    "    return st\n",
    "\n",
    "import os\n",
    "for root,dirs,files in os.walk(source_path,topdown=False): \n",
    "    for file in files:\n",
    "        filename_path=os.path.join(root,file)\n",
    "        new_filename = rep(file)\n",
    "        new_filename_path=os.path.join(root,new_filename)\n",
    "        os.rename(filename_path,new_filename_path)\n",
    "    for dir in dirs:\n",
    "        dir_path=os.path.join(root,dir)\n",
    "        new_dir = rep(dir)\n",
    "        new_dir_path=os.path.join(root,new_dir)\n",
    "        os.rename(dir_path,new_dir_path)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
